//
//  VideoDetailViewController.m
//  SHShopping
//
//  Created by 坤鼎 on 2019/9/2.
//  Copyright © 2019 kunding. All rights reserved.
//

#import "VideoDetailViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>


@interface VideoDetailViewController ()
//@property (nonatomic, strong) AVPlayerViewController *aVPlayerViewController;

@property (nonatomic, strong) AVPlayer *player;
@property (nonatomic, strong) UILabel *lbDetail;
@property (nonatomic, strong) UIButton *dianzanBtn;
@property (nonatomic, strong) UIButton *shareBtn;
@property (nonatomic, strong) UILabel *lbTitle;

@end

@implementation VideoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}

- (void)initUI {
    //设置播放的url
//    NSString *playString = @"http://static.tripbe.com/videofiles/20121214/9533522808.f4v.mp4";
//    NSURL *url = [NSURL URLWithString:playString];
    
    
    NSURL *url = [NSURL URLWithString:self.videoPath];
    //设置播放的项目
    AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:url];
    //初始化player对象
    self.player = [[AVPlayer alloc] initWithPlayerItem:item];
    //设置播放页面
    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:_player];
    //设置播放页面的大小
    layer.frame = CGRectMake(0, 0, SCREEN_WIDTH, ADAPT_W(211));
//    layer.backgroundColor = [UIColor cyanColor].CGColor;
    //设置播放窗口和当前视图之间的比例显示内容
    layer.videoGravity = AVLayerVideoGravityResizeAspect;
    //添加播放视图到self.view
    for (CALayer *layer in self.view.layer.sublayers) {
        if ([layer class] == [AVPlayerLayer class]) {
            [layer removeFromSuperlayer];
        }
    }
    [self.view.layer addSublayer:layer];
    
    //设置播放进度的默认值
//    self.progressSlider.value = 0;
    //设置播放的默认音量值
    self.player.volume = 1.0f;
    [self.player play];
    
    
    
    
    self.lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(16, GetViewYH(layer) + 15, SCREEN_WIDTH - 32, 45)];
    self.lbDetail = [[UILabel alloc] initWithFrame:CGRectMake(16, GetViewYH(self.lbTitle) + 12, 210, 17)];

    self.shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 16 - 20, GetViewYH(self.lbTitle) + 10, 20, 20)];
    self.dianzanBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 16 - 16 - 20 - 20, GetViewYH(self.lbTitle) + 10, 20, 20)];

//    self.shareBtn.backgroundColor = [UIColor lightGrayColor];
//    self.dianzanBtn.backgroundColor = [UIColor redColor];

    [self.shareBtn addTarget:self action:@selector(share) forControlEvents:UIControlEventTouchUpInside];
    [self.dianzanBtn addTarget:self action:@selector(dianzan) forControlEvents:UIControlEventTouchUpInside];

    self.lbTitle.numberOfLines = 2;
    self.lbTitle.text = self.videoTitle;

    self.lbDetail.text = self.fromName;
    self.lbDetail.textColor = UIColorFromRGB(0x999999);
    self.lbDetail.font = FONT(12);

    [self.shareBtn setImage:ImageNamed(@"分享") forState:UIControlStateNormal];
    [self.dianzanBtn setImage:ImageNamed(@"点赞1") forState:UIControlStateNormal];

//    [self.view addSubview:self.AVBtn];
    [self.view addSubview:self.lbTitle];
    [self.view addSubview:self.lbDetail];
    [self.view addSubview:self.shareBtn];
    [self.view addSubview:self.dianzanBtn];
}


- (void)share {
    [SXLoadingView showAlertHUD:@"share" duration:1];
}

- (void)dianzan {
    [SXLoadingView showAlertHUD:@"dianzan" duration:1];
}

@end
